package com.szeldon.pj.jps.exp;

import com.szeldon.pj.jps.data.store.SBAStore;
import com.szeldon.pj.jps.datastore.SimpleObject;
import com.szeldon.pj.jps.envs.ENVS;
import com.szeldon.pj.jps.qres.AbstractQueryResult;
import com.szeldon.pj.jps.qres.BagResult;
import com.szeldon.pj.jps.qres.QResStack;
import com.szeldon.pj.jps.visitor.ASTVisitor;

public class BagNaryExpression extends NaryExpression {

	/**
	 * 
	 * @param expressions
	 */
	public BagNaryExpression(Expression... expressions) {
		super(expressions);
	}

	/**
	 * 
	 * @param astVisitor
	 * @param envs
	 * @param qResStack
	 * @param store
	 */
	public void accept(ASTVisitor astVisitor, ENVS envs, QResStack qResStack, SBAStore store) {
		BagResult expressionResult = new BagResult();

		for (Expression currentExpression : expressions) {
			astVisitor.accept(currentExpression);

			AbstractQueryResult currentExpressionResult = qResStack.pop();
			expressionResult.addResult(currentExpressionResult);
		}

		qResStack.push(expressionResult);

	}

	@Override
	public int compareTo(SimpleObject object) throws IllegalStateException {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public String getValueAsString() {
		return "bag";
	}
}
